<style lang="less">
    .modal-box img{
        width: 600px;
    }
</style>

<template>
    <Card>
        <p slot="title">
            <Breadcrumb>
                <BreadcrumbItem to="/dashboard/index"><Icon type="ios-home-outline"></Icon> 首页</BreadcrumbItem>
                <BreadcrumbItem to="/sys/setting"><Icon type="ios-list"></Icon> 系统配置</BreadcrumbItem>
                <BreadcrumbItem to="/sms/setting"><Icon type="ios-copy-outline"></Icon> 算力比例</BreadcrumbItem>
            </Breadcrumb>
        </p>
        <Row>
            <Col span="1">.</Col>
            <Col span="10">
            <Row>
                <p style="text-align: center;margin: 20px 0;">智力算力比例</p>
                <Form ref="staticForm" :rules="formRules" :label-width="100">
                    <FormItem  v-for="item in staticList" :label="item.index" prop="item.index">
                        <Input type="text" v-model="item.value"></Input>
                        <span>百分比换算：{{item.value*100 | toFixed}}%</span>
                    </FormItem>
                    <FormItem>
                        <Button type="primary" @click="handleSubmit('staticForm')" icon="checkmark-round">确认修改</Button>
                    </FormItem>
                </Form>
            </Row>
            </Col>
            <Col span="2">.</Col>
            <Col span="10">
            <Form ref="dynamicForm" :rules="formRules" :label-width="100">
                <p style="text-align: center;margin: 20px 0;">链接算力比例</p>
                <FormItem  v-for="item in dynamicList" :label="item.index" prop="item.index">
                    <Input type="text" v-model="item.value"></Input>
                    <span>百分比换算：{{item.value*100 | toFixed}}%</span>
                </FormItem>
                <FormItem>
                    <Button type="primary" @click="handleSubmit('dynamicForm')" icon="checkmark-round">确认修改</Button>
                </FormItem>
            </Form>
            </Col>
        </Row>
    </Card>
</template>
<script>
    import Util from '../../libs/util';

    export default {
        components: {},
        data () {
            return {
                staticList: [],
                dynamicList: [],
                dataForm: {
                    opwd: '',
                    date_s: '',
                    date_e: '',
                    type: '',
                    user_id: ''
                },
                formRules: {
                }
            };
        },
        mounted: function () {
            this.$nextTick(function () {
                this.getList();
            });
        },
        created: function () {
            // this.$nextTick(function () {
            //     this.getList();
            // });
        },
        filters: {
            toFixed(value) {
                return value.toFixed(2);
            }
        },
        methods: {
            getList: function (params) {
                Util.ajax.post(`/adminapi/sysconfig/autoconfig`).then(response => {
                    this.staticList = response.data.data.t_coin_j_sacle;
                    this.dynamicList = response.data.data.t_coin_d_sacle;
                });
            },
            handleReset (name) {
                this.$refs[name].resetFields();
            },
            handleSubmit: function (name) {
                this.$refs['staticForm'].validate((valid) => {
                    let formData;
                    let index;
                    if(name == 'staticForm') {
                        formData = this.staticList;
                        index = 't_coin_j_sacle';
                    }else if(name == 'dynamicForm') {
                        formData = this.dynamicList;
                        index = 't_coin_d_sacle';
                    }
                    if (valid) {
                        Util.ajax.post('/adminapi/sysconfig/editauto', {index:index, data:formData}).then(response => {
                            if(response.data.code == 0) {
                                this.$Message.success('修改成功');
                            }else {
                                this.$Message.error('修改失败');
                            }
                        });
                    }
                });
            }

        }
    };
</script>
